"""
 -*- coding: utf-8-*-
 @File: page_owner_mgt.py
 @Author: chen
 @time: 2024/01/10/ 20:21
"""
from ui_test.page_po_test.page_business.page_base import BasePage


class OwnerMgtPage(BasePage):
    def goto_pet_mgt_page(self, first_name, last_name):
        owner_name = f"{first_name} {last_name}"
        btn_owner = (self.by.XPATH, f'//*[text()="{owner_name}"]')
        self.logger.info(f"点击owner：{owner_name}")
        self.do_click(btn_owner)
        from ui_test.page_po_test.page_business.page_pet_mgt import PetMgtPage
        self.logger.info("进入宠物管理页面")
        return PetMgtPage(self.driver)

    def goto_create_owner_page(self):
        btn_add = (self.by.XPATH, '//*[text()="Add Owner"]')
        self.logger.info(f"点击添加宠物按钮")
        self.do_click(btn_add)
        from ui_test.page_po_test.page_business.page_create_owner import CreateOwnerPage
        self.logger.info("进入添加宠物主人页面")
        return CreateOwnerPage(self.driver)

    def create_owner(self, first_name, last_name, address, city, telephone):
        self.goto_create_owner_page().\
            create_to_owner_mgt_page(first_name, last_name, address, city, telephone)
        return self

    def owner_is_exist(self, first_name, last_name):
        """判断宠物主人是否存在"""
        owner_name = f"{first_name} {last_name}"
        btn_owner = (self.by.XPATH, f'//*[text()="{owner_name}"]')
        owner_ele = self.do_finds(btn_owner)
        if owner_ele:
            self.logger.info(f"宠物主人{owner_name}--->已存在")
            return True
        else:
            self.logger.info(f"宠物主人{owner_name}--->不存在")
            return False
